package com.example.io_demo.io;

import jdk.nashorn.api.scripting.URLReader;
import org.springframework.util.StringUtils;

import java.io.*;
import java.net.URL;

/**
 * @author zhaoyunlong
 * @date 2020/11/2
 * @description
 */
public class BaiduTest {

    public static void main(String[] args) {
        try (BufferedWriter bufferedWriter = new BufferedWriter(new FileWriter("baidu.html"));
             BufferedReader bufferedReader = new BufferedReader(new URLReader(new URL("http://www.baidu.com")))) {

            String str = "";
            //可以实现正行的读取和写入
            while ((str = bufferedReader.readLine()) != null) {
                bufferedWriter.write(str);
                bufferedWriter.newLine();
            }

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
